import axios from '@/utils/axios';

/**
 * get camera list
 * @author LXBsmile
 * @date 2019-11-07
 * @param {Object} post request body
 * @returns {Object} 包含分页信息的摄像头列表
 */
export function getList(post) {
  return axios.post('/plat/camera/info/list', post).then(res => {
    if (res.code === 1) {
      return res.data;
    } else {
      throw res.msg;
    }
  })
}

/**
 * 获取摄像头视频地址
 * @author LXBsmile
 * @date 2019-11-08
 * @param {String} cameraId 摄像头code
 * @returns {Object}
 */
export function getVideoUrl(cameraId) {
  const params = { cameraId }
  return axios.get('/plat/hikvison/getCameraUrlById', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function saveCamera(row) {
  return axios.post('plat/camera/info/save', row).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function delCamera(cameraId) {
  return axios.get('plat/camera/info/delete', { params: { cameraId } }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}
